package com.hsnn.medstgmini.base.dict.controller;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hsnn.medstgmini.base.dict.service.DicAreaLogManager;
import com.hsnn.medstgmini.util.Pagination;
/**
 * 
 *@category 地区字典日志管理
 *@author 邱磊
 *@date 2015年6月18日 上午8:26:38
 */
@Controller
@RequestMapping("/dicAreaLog")
public class DicAreaLogController {
	
	private static final Logger log = Logger.getLogger(DicAreaLogController.class);
	
	private DicAreaLogManager dicAreaLogManager;
	
	@Autowired
	private  HttpServletRequest request;

	@Autowired
	public void setDicAreaLogManager(DicAreaLogManager dicAreaLogManager) {
		this.dicAreaLogManager = dicAreaLogManager;
	}

	/**
	 * 基础库 数据字典 地区字典 维护记录
	 * @param page
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping("/toLogList")
	public String getHisList() throws UnsupportedEncodingException{
		request.setAttribute("areaid", request.getParameter("areaid"));
		String areaName = new String(request.getParameter("areaName").getBytes("ISO8859-1"),"utf-8");
		request.setAttribute("areaName", areaName);
		return "/base/dict/areaLog";
	}
	
	//获取维护记录列表
	@RequestMapping("/getLogDataList" )
	@ResponseBody
	public Pagination getDataHisInfo(){
		Pagination page = new Pagination(request);
		page.getConditions().put("areaid", request.getParameter("areaid"));
		page.getConditions().put("startDate", request.getParameter("startDate"));
		page.getConditions().put("endDate", request.getParameter("endDate"));
		log.info("areaid=" + request.getParameter("areaid") + ", startDate = " 
		         + request.getParameter("startDate") + ", endDate = " + request.getParameter("endDate"));
		page = dicAreaLogManager.getLogData(page);
		return page;
	}
	
	
	/**
	 * 基础库 数据字典 地区字典 根据id查询地区 日志详情
	 * @param page
	 * @return
	 */
	@RequestMapping("/toAreaLogDetail")
	public String toAreaLogDetail(){
		log.info("enter toAreaLogDetail method!");
		Pagination  page = new Pagination();
		page.getConditions().put("logId", request.getParameter("logId"));
		page = dicAreaLogManager.getAreaLogDetail(page);
		request.setAttribute("list", page.getRows());
		request.setAttribute("info", page.getConditions());
		return "/base/dict/areaLogDetail";	
	}
}